using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RunningDustEffect : MonoBehaviour
{
    public ParticleSystem ps;
    public bool isPlayerMoving;

    private void Start()
    {
       transform.Find("Particle System").TryGetComponent<ParticleSystem>(out ps);
    }

    private void Update()
    {
        if(Input.GetKey(KeyCode.A)) 
        {
            isPlayerMoving = true;
        }
        if (Input.GetKeyUp(KeyCode.A))
        {
            isPlayerMoving = false;
        }
        if(Input.GetKey(KeyCode.D)) 
        {
            isPlayerMoving = true;
        }
        if (Input.GetKeyUp(KeyCode.D))
        {
            isPlayerMoving = false;
        }
        if(Input.GetKeyDown(KeyCode.Space))
        {
            isPlayerMoving = false;
        }
        DustEffectUpdate();
    }

    public void DustEffectUpdate()
    {
        if (isPlayerMoving)
        {
            if (ps.isPlaying)
            {
                return;
            }
            ps.Play();
        }
        else
        {
            ps.Stop();
        }
    }
}
